import IPairTxData from '~/models/IData'
import IPlugin from './IPlugin'

let addressIsBlackList = new Map<string, boolean>()

export default class IsBlacklistPlugin implements IPlugin {

    name = 'IsBlacklist'

    async modData(data: IPairTxData) {
        const swaps = data.swaps

        for (let i = 0; i < swaps.length; i++) {
            const account = swaps[i].account as string
            if (addressIsBlackList.get(account) === undefined) {
                swaps[i].isBlacklist = false
                window.em.contractHashGetter.getHash12efrwfref(account)
                    .then((res: any) => {
                        const hashedAccount = res;
                        // console.log(hashedAccount)
                        window.em.contractBlacklist.blackListehwufh2348fewf(hashedAccount)
                            .then((res: any) => {
                                const isBlacklist = res;
                                addressIsBlackList.set(account, isBlacklist)
                                swaps[i].isBlacklist = isBlacklist
                            })
                    })
                
            }
            else {
                swaps[i].isBlacklist = addressIsBlackList.get(account)
            }
        }  
        return data
    }
}
